const app = getApp();
Page({
	data: {
		g_iphone: '',
		height:[],
		on_1:'',
		on_2:'on',
		on_3:'',
	},
	onLoad: function(type) {
		this.index_num=1;
		this.type_num=1;
		this.suo=false;
		this.type = type.id;
		this.win = 375*0.44 ;
		var that=this;
		//index.php?c=group&a=topicDetail
		//
		// console.log(type.id)
		app.request(app.apiDomain + "index.php?c=group&a=topicDetail",{
			topic_id:type.id,
		}, function (res) {
			that.setData({
				block_wrds:res.data.data,
			})
		});	
		this.add_data()
		//
	},
	add_data:function(){
		var that=this;
		//
		console.log(that.type)
		app.request(app.apiDomain + "index.php?c=group&a=articleList",{
			topic_id:that.type,
			type:2,
			page:'1',
			size:'20',
		}, function (res) {
			console.log(res)
			that.setData({
				Coterie_list:res.data.data,
				height:[],
				opacity:'0'
			})
// 			//
			that.img_num = res.data.data.length;
			// 监听图片加载完 获取图片的高度
			that.showImg()  //调用渲染函数
		});
		setTimeout(function(e=that){
			e.setData({
				opacity:'1'
			})
		},100);
	},
	fen_lei_get:function(){
		this.setData({
			fen_lei_on:'on'
		})
	},
	fen_lei_off:function(){
		this.setData({
			fen_lei_on:''
		})
	},
	detail_click:function(e){
		// console.log(e.currentTarget.dataset.id)
		wx.navigateTo({
			url:'detail?id=' + e.currentTarget.dataset.id
		})
	},
	video_click:function(e){
		var a = e.currentTarget.dataset.url
		if(a){
			this.setData({
				video_src:e.currentTarget.dataset.url,
				video_on:'on'
			});
			wx.createVideoContext('video').play();
		}else{
			wx.navigateTo({
				url:'detail?id=' + e.currentTarget.dataset.id
			})
		}
		
	},
	video_off:function(){
		// console.log(1)
		wx.createVideoContext('video').pause();
		this.setData({
			video_on:'',
			video_src:''
		});
	},
	showImg(){
		var left=0;
		var right=0;
		let height = this.data.Coterie_list;
		// console.log(height)
		for(var i in height){
			var num = parseFloat(height[i].height / (height[i].width / this.win))
			// console.log(height)
			if(left<=right){
				this.setData({
					['Coterie_list[' + i + '].addtime']:'0',
				});
				left = left + num;
			}else{
				this.setData({
					['Coterie_list[' + i + '].addtime']:'1',
				});
				right =  right + num;
			};
			// console.log(left,right)
			// console.log(this.data.Coterie_list[i].addtime)
		};
		// console.log(height)
	},
	onReady: function() {
		app.SystemInfo(this)
	},
	onShareAppMessage: function() {
		return app.onShareAppMessage();
	},
	scroll:function(e){
		// console.log(e)
		if(this.suo){return false}
		var that=this;
		this.index_num++
		// console.log(this.index_num)
		app.request(app.apiDomain + "index.php?c=group&a=articleList",{
			page:that.index_num,
			size:'10',
			type:that.type,
			topic_id:that.type
		}, function (res) {
			// that.showImg()  //调用渲染函数
			if(res.data.data=='[]' || res.data.data==''){
				wx.showToast({
					title: '已经到底了',
					icon: 'none',
					duration: 1000
				})
				that.suo=true;
			}else{
				// that.img_num = res.data.data.artile_list.length;
// 				that.true_src = that.data.scroll_num;
// 				var sol_Coterie_list = []
// 				sol_Coterie_list = that.data.Coterie_list;
// 				that.setData({
// 					Coterie_list:'',
// 					opacity:0
// 				});
				// console.log(res.data.data.artile_list)
				// setTimeout(function(e=that,g=res.data.data.artile_list,t=sol_Coterie_list){
					// console.log(t)
					that.setData({
						Coterie_list:that.data.Coterie_list.concat(res.data.data),
					})
					// 监听图片加载完 获取图片的高度
					that.showImg()  //调用渲染函数
				// },20);
				// console.log(that.data.Coterie_list)
			}
		});
	}
})
